﻿using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Caching.Memory;

namespace CYZHAPI.Middlewares
{
    public static class ApiAuthorizedExtensions
    {
        public static IApplicationBuilder UseApiAuthorized(this IApplicationBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return builder.UseMiddleware<ApiAuthorizedMiddleware>();
        }

        public static IApplicationBuilder UseApiAuthorized(this IApplicationBuilder builder, IMemoryCache memoryCache)
        {//private IMemoryCache _memoryCache;
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (memoryCache == null)
            {
                throw new ArgumentNullException(nameof(memoryCache));
            }
            
            return builder.UseMiddleware<ApiAuthorizedMiddleware>(memoryCache);
        }
    }
}